package com.yaodian100.ec.product.web;

import java.io.File;
import java.io.FilenameFilter;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.admin.entity.Group;
import com.yaodian100.core.admin.entity.Role;
import com.yaodian100.core.admin.entity.User;
import com.yaodian100.core.admin.entity.UserPermission;
import com.yaodian100.core.admin.entity.Permission.Type;
import com.yaodian100.core.admin.service.GroupService;
import com.yaodian100.core.admin.service.UserService;
import com.yaodian100.core.admin.utils.AdminHelper;
import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.entity.SimplePager;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.core.common.utils.DateUtil;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.core.menu.entity.Menu;
import com.yaodian100.ec.category.entity.Category;
import com.yaodian100.ec.category.service.CategoryService;
import com.yaodian100.ec.common.EcConstant;
import com.yaodian100.ec.image.entity.Image;
import com.yaodian100.ec.image.service.ImageService;
import com.yaodian100.ec.product.entity.AddOnProduct;
import com.yaodian100.ec.product.entity.Brand;
import com.yaodian100.ec.product.entity.Product;
import com.yaodian100.ec.product.entity.ProductCategory;
import com.yaodian100.ec.product.entity.ProductPromotionFlag;
import com.yaodian100.ec.product.service.Product2Service;
import com.yaodian100.ec.shelf.entity.Shelf;
import com.yaodian100.ec.shelf.service.ShelfService;
import com.yaodian100.ec.supplierapply.entity.SupplierApply;
import com.yaodian100.ec.supplierapply.service.SupplierApplyService;
import com.yaodian100.ec.timelimitsale.service.TimeLimitSaleService;

public class PickProduct2Action extends ActionSupport implements Preparable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8477240071615551712L;
	private final Logger logger = LoggerFactory.getLogger(PickProduct2Action.class);
	private ShelfService shelfService;
	private Product2Service productService;
	private CategoryService categoryService;
	private ImageService imageService;
	private UserService userService;
	private GroupService groupService;
	private DomainService<Menu> menuService;
	@Resource
	private SupplierApplyService supplierApplyService;
	private CommonCriteria criteria;
	private SimplePager pager;
	// private List<ViewPickProduct2> viewPickProducts;
	private List<Map<String, Object>> pickProductList;
	private Product product;
	private Shelf shelf;
	private ProductPromotionFlag productPromotionFlag;
	private ProductCategory productCategory;
	private String jsonOrderNotice;
	private Category category;
	private String fullCategoryPath;
	private String categoryResult;
	private String jsonCategoryPath;
	private String jsonShelfDateExist;

	private Map<String, String> fileMap;
	private List<Brand> brands;// 品牌
	private List<Category> rootCategories;
	private Map<String, String> mapRootCategories;
	private AddOnProduct addOnProduct;
	private List<AddOnProduct> addOnProducts;
	private Map<String, String> productNameMap;
	private Map<Long, String> productCategoryMap;
	private List<ProductCategory> editProductCategories;
	private Menu attributeMenu;
	private List<User> users;
	private List<Group> groups;
	private Menu expireManageMenu;
	private Menu returnRuleMenu;// 退换货条件
	private String expireManage;
	private String isAntiUnpacking;
	/* 月历default值 */
	private String minDate;
	private String today;

	/* 查询列表页面参数 */
	private String mainProductIdParam;// 活动商品编号
	private String promoteNameParam;// 活动商品名称关键字
	private String addonProductIdParam;// 搭配商品编号
	private String startDateParam;// 活动开始时间
	private String endDateParam;// 活动结束时间
	private String productAttributeParam;// 商品属性
	private String supplierParam;// 供应商
	private String editbrand;
	private String brandParam;
	private String brandName;
	private String categoryLevel1Param;// 馆别
	private String categoryLevel2Param;// 次分类
	private String organizationParam;// 部门
	private String pmParam;// 负责人
	private String returnRule;// 退换货条件
	private String nmMustOrderBuyParam;// 限立即购买
	/* 商品主檔/flag页面参数 */
	private String supplierCompanyName;
	private String editTwSupplier;// 台湾馆供应商
	private String twSupplierCompanyName;
	private String productIdParam;
	private String shelfIdParam;
	private String promoteName;
	private String productName;
	private String brief;
	private String description;
	private String details;
	private String orderNotice;
	private String supplierId;
	private String pm;
	private String organization;
	private String categoryId;
	private String brand;
	private String listPrice;
	private String flag01;
	private String flag02;
	private String flag03;
	private String flag04;
	private String flag05;
	private String flag06;
	private String flag07;
	private String flag08;
	private String flag09;
	private String flag10;
	private String flag11;
	private String flag12;
	private String flag13;
	private String flag14;
	private String flag15;
	private String flag16;
	private String showSeq;
	// private String categoryPath;
	private String mainCategoryId;
	private String[] prdtDelete;
	private String productAttribute;
	private String isScm;
	private String scmNotice;
	private String prpsShelfPrice;
	private String graphicType;
	private String isValidateNum = "N";
	private String isScmParam;
	private String nmMustOrderBuy;
	/* 上传商品图片页面 参数 */
	private File[] imageMFiles;
	private File[] imageFiles;
	private List<Image> images;
	private String productmgTypeParam;
	private String[] imageFilesFileNames;
	private String picDesc;
	private String[] deletePic;
	private Image image;
	private String imgId;
	private File[] imageDes;
	private int imgSize;

	private File[] picImgs;
	private String[] picImgDetails;
	private String[] picImgDescs;
	private String[] picImgShowSeqs;
	private String[] imgIds;
	private Map<String, String> imageTypeMap;
	private String selImageType;

	/* 商品目录页面参数 */
	private List<ProductCategory> productCategories;
	// private Long mainCategory;
	private String lastMainCategoryId;
	private String mainCategoryText;
	private String editFlag;
	private String userPermissions = "";

	/* n选m主檔页面参数 */
	// private String pickProductId;
	private Product jsonProduct;
	private String finalAddOnData;
	private String finalRemoveData;

	/* 上架檔页面 参数 */
	private String shelfPrice;
	private String pickupQty;
	private String startDate;
	private String endDate;
	private String timeStart;
	private String timeEnd;
	DateFormat format = new SimpleDateFormat(EcConstant.PATTERN_TIMESTAMP_HH_MM);

	// 雙屬性 start
	private String copy;
	private String paramProductId;
	private Map<String, String> addmProductSupplierMap;
	private List<String> newAddProducts;
	private String[] addPrds;
	private String[] delPrds;
	private Map<String, String> modifymProductSupplierMap;
	private Map<String, String> modifymProductScmMap;
	private List<Shelf> shelfs;
	private String[] shelfStatus;
	private String shelfStParam;
	private String validateNumParam;
	private Menu shelfStatusMenu;
	private Menu isScmMenu;
	private Shelf shelfNow;
	private String limitBuyParam;

	private String mainCategoryPath;
	private String tempCategoryFullPath = "";
	private String saveFlag = "";
	private String nowStep = "1";
	private Menu shelfQueryStatusMenu;
	@Resource
	private TimeLimitSaleService timeLimitSaleService;

	// 雙屬性 end

	public String addShelf() throws NumberFormatException, CoreException {
		if (StringUtils.isBlank(productIdParam) || StringUtils.length(productIdParam) != 8
				|| !NumberUtils.isNumber(productIdParam)) {
			addActionError("传入参数错误");
		} else {
			product = productService.get(productIdParam);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
			} else {
				shelf = new Shelf();
				shelfPrice = "";
				pickupQty = "";
			}
		}
		return "editShelf";
	}

	/**
	 * 检查上架编号是否存在
	 * 
	 * @param sId
	 * @return
	 * @throws NumberFormatException
	 * @throws CoreException
	 */
	Shelf checkShelfId(String sId) throws NumberFormatException, CoreException {
		if (StringUtils.isBlank(sId)) {
			return null;
		} else {
			Shelf shelf = shelfService.get(Long.parseLong(sId));
			if (null == shelf) {
				return null;
			} else {
				return shelf;
			}
		}
	}

	/**
	 * 检视商品是否是同一供应商
	 * 
	 * @return
	 * @throws CoreException
	 */
	private boolean checkTheSameSupplier(String finalAddOnData, String pickProductId) throws CoreException {
		boolean sameSupplier = false;
		Map<String, String> pdIdCheckMap = new HashMap<String, String>();
		Map<String, String> scmCheckMap = new HashMap<String, String>();
		Map<String, Map<String, String>> resultMap = new HashMap<String, Map<String, String>>();
		// m
		Product pdSuplier = productService.get(pickProductId);
		if (null != pdSuplier) {
			resultMap = checkSameScmMap(pdSuplier, pdIdCheckMap, scmCheckMap);
		}
		// n
		pdSuplier = productService.get(productIdParam);
		if (null != pdSuplier) {
			pdIdCheckMap.put(pdSuplier.getSupplierId(), pdSuplier.getSupplierId());
			if (Arrays.asList("B", "N").contains(pdSuplier.getIsScm())) {// N或B一律視為N
				scmCheckMap.put("N", pdSuplier.getSupplierId());
			} else {
				scmCheckMap.put(pdSuplier.getIsScm(), pdSuplier.getSupplierId());
			}
			criteria = new CommonCriteria();
			criteria.addEq("mainProductId", productIdParam);
			addOnProducts = productService.getAddOnProductList(0, -1, criteria, null);
			if (addOnProducts.size() > 0) {// 已存在的AddOnProduct，由DB抓出
				for (int ipnm = 0; ipnm < addOnProducts.size(); ipnm++) {
					pdSuplier = productService.get(addOnProducts.get(ipnm).getAddOnProductId());
					if (null != pdSuplier) {
						resultMap = checkSameScmMap(pdSuplier, pdIdCheckMap, scmCheckMap);
					}
				}
			} else {// 新增時，由前端頁面帶入
				String[] spProdId = finalAddOnData.split(";");
				if (StringUtils.isNotBlank(finalAddOnData)) {
					for (int ipnm = 0; ipnm < spProdId.length; ipnm++) {
						pdSuplier = productService.get(spProdId[ipnm]);
						if (null != pdSuplier) {
							resultMap = checkSameScmMap(pdSuplier, pdIdCheckMap, scmCheckMap);
						}
					}
				}
			}
		}
		if (resultMap.get("pdIdCheckMap").size() == 1 && resultMap.get("scmCheckMap").size() == 1) {
			sameSupplier = true;
		} else {
			sameSupplier = false;
		}
		return sameSupplier;
	}

	Map<String, Map<String, String>> checkSameScmMap(Product product, Map<String, String> pdIdCheckMap,
			Map<String, String> scmCheckMap) {
		if (Arrays.asList("N", "B").contains(product.getIsScm())) {
			if (!Arrays.asList("000000", "000953").contains(product.getSupplierId())) {
				pdIdCheckMap.put(product.getSupplierId(), product.getSupplierId());
				scmCheckMap.put("N", product.getSupplierId());// N或B一律視為N
			}
		} else {
			pdIdCheckMap.put(product.getSupplierId(), product.getSupplierId());
			scmCheckMap.put(product.getIsScm(), product.getSupplierId());
		}
		Map<String, Map<String, String>> checkMap = new HashMap<String, Map<String, String>>();
		checkMap.put("pdIdCheckMap", pdIdCheckMap);
		checkMap.put("scmCheckMap", scmCheckMap);
		return checkMap;
	}

	public String deletePic() throws Exception {
		if (null != deletePic) {
			imageService.deletePic(deletePic);
		}
		// 複蓋原圖檔
		String picImgNo;
		String picImgDesc;
		String picImgShowSeq;
		String msg;
		StringBuffer msgBuffer = new StringBuffer();
		int i = 0;
		if (null != picImgs) {
			File[] tempFile = new File[1];
			for (String picImgDetail : picImgDetails) {
				picImgNo = picImgDetail.split("θ")[0];
				picImgDesc = picImgDetail.split("θ")[1];
				picImgShowSeq = picImgDetail.split("θ")[2];
				tempFile[0] = picImgs[i];
				msg = imageService.editImgDetail(Long.parseLong(picImgNo), tempFile, picImgDesc, picImgShowSeq);
				if (StringUtils.isNotBlank(msg)) {
					addActionMessage(msg);
				}
				i++;
			}
		}
		i = 0;
		for (String picId : imgIds) {
			picImgDesc = picImgDescs[i];
			picImgShowSeq = picImgShowSeqs[i];
			imageService.editImgDetail(Long.parseLong(picId), null, picImgDesc, picImgShowSeq);
			i++;
		}
		deletePic = null;
		picImgs = null;
		imgIds = null;
		return viewUploadProdImg();
	}

	public String editImgDetail() throws Exception {
		imageService.editImgDetail(Long.parseLong(imgId), imageDes, picDesc);
		return viewUploadProdImg();
	}

	/**
	 * 载入新增/编辑n选m商品
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String editPickProduct() throws CoreException {
		if (StringUtils.isBlank(productIdParam) || StringUtils.length(productIdParam) != 8
				|| !NumberUtils.isNumber(productIdParam)) {
			addActionError("传入参数错误");
		} else {
			product = productService.get(productIdParam);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
			} else {
				shelf = checkShelfId(shelfIdParam);
				productNameMap = findAddOnProductMap(productIdParam);
				SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
				if (null != supplierApply) {
					supplierCompanyName = supplierApply.getCompanyName();
				}
			}
		}
		nowStep = "3";
		return "editPickProduct";
	}

	/**
	 * 载入新增/编辑商品主檔/flag资料
	 * 
	 * @return
	 * @throws CoreException
	 * @throws NumberFormatException
	 */
	public String editProduct() throws NumberFormatException, CoreException {
		if (StringUtils.isNotBlank(productIdParam)) {
			if (StringUtils.length(productIdParam) != 8 || !NumberUtils.isNumber(productIdParam)) {
				addActionError("传入参数错误");
				return "editProduct";
			}
			product = productService.get(productIdParam);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
				return "editProduct";
			}
			pm = product.getPmID();
			organization = product.getOrganizationPath();
			supplierId = product.getSupplierId();
			setEditbrand(StringUtils.defaultString(product.getProductBrand()));
			setIsScm(product.getIsScm());
			setExpireManage(product.getExpireManage());
			setIsAntiUnpacking(product.getIsAntiUnpacking());
			if (StringUtils.isBlank(product.getGraphicType())) {
				setGraphicType("S");
			} else {
				setGraphicType(product.getGraphicType());
			}

			if (null != product.getProductBrand() || StringUtils.isNotBlank(product.getProductBrand())) {
				// brandParam = product.getProductBrand();
				Brand brand = productService.getBrandByBrandId(product.getProductBrand());
				if (null != productService.getBrandByBrandId(product.getProductBrand())) {
					setBrandName(brand.getBrandName());
				} else {
					setBrandName("");
				}
			} else {
				// setBrandParam("");
				setBrandName("");
			}
			productAttribute = product.getIsDelete();
			returnRule = product.getReturnRule();
			nmMustOrderBuy = product.getNmMustOrderBuy();
			productPromotionFlag = productService.getProductPromotionFlag(productIdParam);
			fileMap = new HashMap<String, String>();
			fileMap = readProductFromFile(productIdParam);
			Category category = categoryService.get(Long.parseLong(String.valueOf(product.getMainCategoryID())));
			product.setCategory(category);
			// categoryPath = product.getCategory().getCategoryPath();
			mainCategoryPath = product.getCategory().getCategoryPath();
			SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
			if (null != supplierApply) {
				supplierCompanyName = supplierApply.getCompanyName();
			}
			if (StringUtils.isNotBlank(product.getTwSupplierId())) {
				SupplierApply twSupplierApply = supplierApplyService.get(product.getTwSupplierId());
				if (null != twSupplierApply) {
					editTwSupplier = product.getTwSupplierId();
					twSupplierCompanyName = twSupplierApply.getCompanyName();
				}
			}

			if (null != productPromotionFlag) {
				if (StringUtils.isNotBlank(productPromotionFlag.getFlag04())) {
					flag04 = "true";
				} else {
					flag04 = "";
				}

				if (StringUtils.isNotBlank(productPromotionFlag.getFlag05())) {
					flag05 = "true";
				} else {
					flag05 = "";
				}

				if (StringUtils.isNotBlank(productPromotionFlag.getFlag06())) {
					flag06 = "true";
				} else {
					flag06 = "";
				}

				if (StringUtils.isNotBlank(productPromotionFlag.getFlag16())) {
					flag16 = "true";
				} else {
					flag16 = "";
				}

			}

			// 查询已选的主分类详细路径
			if (null != product.getCategory()) {
				tempCategoryFullPath = categoryService.makeCategorieURL(Long.valueOf(product.getMainCategoryID()), false);
				mainCategoryPath = product.getCategory().getCategoryPath();
				mainCategoryId = String.valueOf(product.getMainCategoryID());

			}
			// 载入分身资料(濾掉主分類資料)
			productCategories = new ArrayList<ProductCategory>();
			Iterator<ProductCategory> iter = product.getProductCategories().iterator();
			while (iter.hasNext()) {
				ProductCategory pc = iter.next();
				if (!pc.getCategoryId().toString().equals(product.getCategory().getId().toString())) {
					productCategories.add(pc);
				}
			}

			productCategoryMap = findProductCategoryMap(productCategories, product);
			User user = AdminHelper.getUser();
			if (null != user) {
				// 若 user 是 PM部門, 檢核 product.category 的 orgnizationPath 是否合乎規定
				int i = 0;
				for (UserPermission up : user.getPermissions(Type.CATEGORY).values()) {
					userPermissions = userPermissions + StringUtils.trim(up.getPermissionCode());
					if (i != user.getPermissions(Type.CATEGORY).values().size() - 1) {
						userPermissions = userPermissions + ",";
					}
					i++;
				}
			}
			nowStep = "1";
			Long luxAddOnCount = productService.getLuxAddOnCount(productIdParam);
			Long nmlAddOnCount = productService.getNmlAddOnCount(productIdParam);
			Map<String, Integer> tmpAddOnTypeSize = new HashMap<String, Integer>();
			tmpAddOnTypeSize.put("LUX", luxAddOnCount.intValue());
			tmpAddOnTypeSize.put("NML", nmlAddOnCount.intValue());
			product.setAddOnTypeSize(tmpAddOnTypeSize);
		} else {
			product = new Product();
			supplierId = "";
			supplierCompanyName = "";
			editbrand = "";
			brandParam = "";
			brandName = "";
			// categoryPath = "";
			mainCategoryPath = "";
			isScm = "N";
			expireManage = "EM01";
			isAntiUnpacking = "N";
			isValidateNum = "N";
			product.setGraphicType("S");
			flag01 = null;
			flag02 = null;
			flag03 = null;
			flag04 = null;
			flag05 = null;
			flag06 = null;
			flag07 = null;
			flag08 = null;
			flag09 = null;
			flag10 = null;
			flag11 = null;
			flag12 = null;
			flag13 = null;
			flag14 = null;
			flag15 = null;
			flag16 = null;
			fileMap = new HashMap<String, String>();
			fileMap.put("brief", "★&nbsp;\n★&nbsp;\n★&nbsp;");
			scmNotice = "";
			productAttribute = "N";
			returnRule = "07_15";
			nmMustOrderBuy = "N";
			editTwSupplier = "";
			twSupplierCompanyName = "";
			setCopy("N");
			// 清空category相關參數
			tempCategoryFullPath = "";
			pm = "";
			organization = "";
			mainCategoryId = "";
			productCategories = new ArrayList<ProductCategory>();
		}
		nowStep = "1";
		return "editProduct";
	}

	/**
	 * 复制商品
	 * 
	 * @return
	 * @throws Exception
	 */
	public String copy() throws Exception {
		if (StringUtils.isBlank(productIdParam) || StringUtils.length(productIdParam) != 8
				|| !NumberUtils.isNumber(productIdParam)) {
			addActionError("传入参数错误");
			return "list";
		}
		Product copyProduct = productService.get(productIdParam);
		if (null == copyProduct) {
			addActionError("查无商品资料(或无该权限查看)");
			return "list";
		}
		product = new Product();
		BeanUtils.copyProperties(copyProduct, product, new String[] { "productId" });

		mainCategoryId = String.valueOf(product.getMainCategoryID());
		mainCategoryPath = product.getCategory().getCategoryPath();
		// 载入分身资料(濾掉主分類資料)
		productCategories = new ArrayList<ProductCategory>();
		Iterator<ProductCategory> iter = product.getProductCategories().iterator();
		while (iter.hasNext()) {
			ProductCategory pc = iter.next();
			if (!pc.getCategoryId().toString().equals(product.getCategory().getId().toString())) {
				productCategories.add(pc);
			}
		}

		productCategoryMap = findProductCategoryMap(productCategories, product);
		User user = AdminHelper.getUser();
		if (null != user) {
			// 若 user 是 PM部門, 檢核 product.category 的 orgnizationPath 是否合乎規定
			int i = 0;
			for (UserPermission up : user.getPermissions(Type.CATEGORY).values()) {
				userPermissions = userPermissions + StringUtils.trim(up.getPermissionCode());
				if (i != user.getPermissions(Type.CATEGORY).values().size() - 1) {
					userPermissions = userPermissions + ",";
				}
				i++;
			}
		}

		setCopy("Y");
		setBrief(productService.readFromFile(copyProduct.getProductId(), "brief"));
		setDescription(productService.readFromFile(copyProduct.getProductId(), "description"));
		setDetails(productService.readFromFile(copyProduct.getProductId(), "details"));
		setOrderNotice(productService.readFromFile(copyProduct.getProductId(), "orderNotice"));
		setScmNotice(productService.readFromFile(copyProduct.getProductId(), "scmNotice"));
		setIsScm(product.getIsScm());
		// setEditsupplier(product.getSupplierId());
		setEditbrand(StringUtils.defaultString(product.getProductBrand()));
		if (null != product.getProductBrand() || StringUtils.isNotBlank(product.getProductBrand())) {
			Brand brand = productService.getBrandByBrandId(product.getProductBrand());
			if (null != productService.getBrandByBrandId(product.getProductBrand())) {
				setBrandName(brand.getBrandName());
			} else {
				setBrandName("");
			}
		} else {
			setBrandName("");
		}

		setPm(product.getPmID());
		setOrganization(product.getOrganizationPath());
		// setEditDeliverGeoRange(product.getDeliverGeoRange());
		setProductAttribute(product.getIsDelete());
		setReturnRule(product.getReturnRule());
		setNmMustOrderBuy(product.getNmMustOrderBuy());
		setExpireManage(product.getExpireManage());
		setIsAntiUnpacking(product.getIsAntiUnpacking());
		setGraphicType(product.getGraphicType());
		setIsValidateNum(product.getIsValidateNum());
		// setUseDeliveryDay(product.getUseDeliveryDay());
		// setDeliveryDay(product.getDeliveryDay());
		if (product.getProductType() == 7) {
			product.setProductType(0);
			// setType("0");
		} else {
			// setType(String.valueOf(product.getProductType()));
		}
		// 查询已选的主分类详细路径
		if (null != product.getCategory()) {
			tempCategoryFullPath = categoryService.makeCategorieURL(Long.valueOf(product.getMainCategoryID()), false);
		}
		productPromotionFlag = productService.getProductPromotionFlag(productIdParam);
		fileMap = new HashMap<String, String>();
		fileMap = readProductFromFile(productIdParam);
		// categoryPath = product.getCategory().getCategoryPath();
		mainCategoryPath = product.getCategory().getCategoryPath();
		SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
		if (null != supplierApply) {
			supplierCompanyName = supplierApply.getCompanyName();
		}
		if (StringUtils.isNotBlank(product.getTwSupplierId())) {
			SupplierApply twSupplierApply = supplierApplyService.get(product.getTwSupplierId());
			if (null != twSupplierApply) {
				editTwSupplier = product.getTwSupplierId();
				twSupplierCompanyName = twSupplierApply.getCompanyName();
			}
		}
		if (null != productPromotionFlag) {
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag04())) {
				flag04 = "true";
			} else {
				flag04 = "";
			}
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag05())) {
				flag05 = "true";
			} else {
				flag05 = "";
			}

			if (StringUtils.isNotBlank(productPromotionFlag.getFlag06())) {
				flag06 = "true";
			} else {
				flag06 = "";
			}
			if (StringUtils.isNotBlank(productPromotionFlag.getFlag16())) {
				flag16 = "true";
			} else {
				flag16 = "";
			}
		}
		productIdParam = "";
		return "editProduct";

	}

	/**
	 * 修改商品属性
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editProductAttribute() throws Exception {
		if (null != prdtDelete) {
			for (int i = 0; i < prdtDelete.length; i++) {
				product = productService.get(prdtDelete[i]);
				product.setIsDelete(productAttribute);
				productService.updatePickProduct(product);
			}
		}
		return search();
	}

	/**
	 * 编辑上架檔资料
	 * 
	 * @return
	 * @throws CoreException
	 * @throws NumberFormatException
	 */
	public String editShelf() throws NumberFormatException, CoreException {
		if (StringUtils.isBlank(productIdParam) || StringUtils.length(productIdParam) != 8
				|| !NumberUtils.isNumber(productIdParam)) {
			addActionError("传入参数错误");
		} else {
			product = productService.get(productIdParam);
			if (null == product) {
				addActionError("查无商品资料(或无该权限查看)");
			} else {
				if (StringUtils.isBlank(shelfIdParam)) {
					shelf = new Shelf();
				} else {
					shelf = shelfService.get(Long.parseLong(shelfIdParam));
				}
			}
		}
		return "editShelf";
	}

	/**
	 * 依主商品id取得n選m商品的商品編號
	 * 
	 * @param productIdParam
	 * @return
	 * @throws CoreException
	 */
	Map<String, String> findAddOnProductMap(String productIdParam) throws CoreException {
		product = productService.get(productIdParam);
		criteria = new CommonCriteria();
		criteria.addEq("mainProductId", productIdParam);
		addOnProducts = productService.getAddOnProductList(0, -1, criteria, null);
		productNameMap = new HashMap<String, String>();
		modifymProductSupplierMap = new HashMap<String, String>();
		modifymProductScmMap = new HashMap<String, String>();
		if (addOnProducts.size() > 0) {
			List<String> tempAddOnProduct = new ArrayList<String>();
			for (AddOnProduct addProduct : addOnProducts) {
				tempAddOnProduct.add(addProduct.getAddOnProductId());
			}
			criteria = new CommonCriteria();
			criteria.addIn("productId", tempAddOnProduct);
			List<Product> products = productService.getList(0, -1, criteria, null);

			for (Product product : products) {
				productNameMap.put(product.getProductId(), product.getProductName());
				SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
				modifymProductSupplierMap.put(product.getProductId(), supplierApply.getCompanyName());
				modifymProductScmMap.put(product.getProductId(), product.getIsScm());
			}
		}
		return productNameMap;
	}

	public String findCategoryPath() throws Exception {
		if (StringUtils.isNotBlank(categoryId)) {
			Long tempCategoryId = Long.parseLong(categoryId);
			jsonCategoryPath = categoryService.get(tempCategoryId).getCategoryPath();
		}
		return "jsonFindCategoryPath";
	}

	/**
	 * 查询商品名称
	 * 
	 * @return
	 * @throws Exception
	 */
	public String findPickProductName() throws Exception {
		// 雙屬性
		List productIds = null;
		Product nProduct = null;
		if (StringUtils.isNotBlank(productIdParam)) {
			nProduct = productService.get(productIdParam);
		}
		if (StringUtils.isNotBlank(paramProductId)) {
			paramProductId = StringUtils.remove(paramProductId, " ");
			paramProductId = StringUtils.remove(paramProductId, "\n");
			String[] pIds = StringUtils.split(paramProductId, ",");
			productIds = new ArrayList();
			for (String p : pIds) {
				productIds.add(p);

			}
		}
		criteria = new CommonCriteria();
		criteria.addIn("productId", productIds);
		List<Product> addProds = productService.getList(0, -1, criteria, null);
		addmProductSupplierMap = new HashMap<String, String>();
		newAddProducts = new ArrayList<String>();
		for (Product product : addProds) {
			StringBuffer sbAddPrd = new StringBuffer();
			sbAddPrd.append(product.getProductId()).append(",");
			sbAddPrd.append(product.getProductName()).append(",");
			sbAddPrd.append(isScmMenu.getOptions().get(product.getIsScm()).getName()).append(",");
			SupplierApply supplierApply = supplierApplyService.get(product.getSupplierId());
			String sCompanyName = "";
			if (null != supplierApply) {
				sCompanyName = supplierApply.getCompanyName();
			}
			sbAddPrd.append(sCompanyName).append(",");
			addmProductSupplierMap.put(product.getProductId(), sCompanyName);
			StringBuffer addOns = new StringBuffer();
			for (AddOnProduct addProduct : addOnProducts) {
				addOns.append(addProduct.getAddOnProductId()).append(";");
			}
			String sVap = validAddProduct(nProduct.getNmMustOrderBuy(), product);
			if ("Y".equals(isScm)) {
				if (!checkTheSameSupplier(addOns.toString(), product.getProductId())) {
					sbAddPrd.append("false").append(",供应商不符合");
				} else {
					// 判断是否有重复的商品编号
					if (addOns.indexOf(product.getProductId()) == -1) {
						if ("true".equals(sVap)) {
							sbAddPrd.append("true");
						} else {
							sbAddPrd.append("false").append(",").append(sVap);
						}
					} else {
						sbAddPrd.append("false").append(",重复的商品编号");
					}
				}
			} else { // PO需選擇同樣為PO商品, 不看供应商
				if ("Y".equals(product.getIsScm())) {
					sbAddPrd.append("false").append(",供应商不符合");
				} else {
					// 判断是否有重复的商品编号
					if (addOns.indexOf(product.getProductId()) == -1) {
						if ("true".equals(sVap)) {
							sbAddPrd.append("true");
						} else {
							sbAddPrd.append("false").append(",").append(sVap);
						}
					} else {
						sbAddPrd.append("false").append(",重复的商品编号");
					}
				}
			}
			newAddProducts.add(sbAddPrd.toString());
		}
		return "jsonFindPickProductName";
	}

	Map<Long, String> findProductCategoryMap(List<ProductCategory> productCategories, Product product)
			throws CoreException {
		productCategoryMap = new HashMap<Long, String>();
		for (ProductCategory productCategory : productCategories) {
			productCategoryMap.put(productCategory.getCategoryId(), categoryService.makeCategorieURL(productCategory
					.getCategoryId(), false)
					+ "," + productCategory.getCategoryPath() + "," + productCategory.getShowSeq());
		}
		return productCategoryMap;
	}

	public String validAddProduct(String nmMustOrderBuy, Product product) {
		String result = "true";
		if (StringUtils.equals("Y", nmMustOrderBuy)) {// 限立即購買商品
			if (product.getProductType() != 7) {
				result = "此商品無法被搭选:商品型态必须为『限立即购买商品』";
			}
		} else {
			if (!(product.getProductType() == 0 || product.getProductType() == 2 || product.getProductType() == 3)) {
				result = "此商品無法被搭选:商品型态必须为『一般』or『赠品』or『配件』";
			}
		}
		if ("Y".equals(product.getIsDelete()) || "Q".equals(product.getIsDelete())) {
			result = "此商品已被删除or此商品的销售状态为可查询不可销售";
		}
		if (!"PRD500".equals(product.getProductStatus())) {
			result = "商品状态不正确";
		}
		if (0 == product.getActivateSpecMajors().size()) {
			result = "此商品無法被搭选:请先设定商品规格";
		}
		return result;
	}

	public String getAddonProductIdParam() {
		return addonProductIdParam;
	}

	public List<AddOnProduct> getAddOnProducts() {
		return addOnProducts;
	}

	public Menu getAttributeMenu() {
		return attributeMenu;
	}

	public String getBrand() {
		return brand;
	}

	public String getBrandName() {
		return brandName;
	}

	public String getBrandParam() {
		return brandParam;
	}

	public List<Brand> getBrands() {
		return brands;
	}

	public String getBrief() {
		return brief;
	}

	public Category getCategory() {
		return category;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public String getCategoryLevel1Param() {
		return categoryLevel1Param;
	}

	public String getCategoryLevel2Param() {
		return categoryLevel2Param;
	}

	// public String getCategoryPath() {
	// return categoryPath;
	// }

	public String getCategoryResult() {
		return categoryResult;
	}

	public CommonCriteria getCriteria() {
		return criteria;
	}

	public String[] getDeletePic() {
		return deletePic;
	}

	public String getDescription() {
		return description;
	}

	public String getDetails() {
		return details;
	}

	public String getEditFlag() {
		return editFlag;
	}

	public List<ProductCategory> getEditProductCategories() {
		return editProductCategories;
	}

	public String getEndDate() {
		return endDate;
	}

	public String getEndDateParam() {
		return endDateParam;
	}

	public Map<String, String> getFileMap() {
		return fileMap;
	}

	public String getFinalAddOnData() {
		return finalAddOnData;
	}

	public String getFinalRemoveData() {
		return finalRemoveData;
	}

	public String getFlag01() {
		return flag01;
	}

	public String getFlag02() {
		return flag02;
	}

	public String getFlag03() {
		return flag03;
	}

	public String getFlag04() {
		return flag04;
	}

	public String getFlag05() {
		return flag05;
	}

	public String getFlag06() {
		return flag06;
	}

	public String getFlag07() {
		return flag07;
	}

	public String getFlag08() {
		return flag08;
	}

	public String getFlag09() {
		return flag09;
	}

	public String getFlag10() {
		return flag10;
	}

	public String getFlag11() {
		return flag11;
	}

	public String getFlag12() {
		return flag12;
	}

	public String getFlag13() {
		return flag13;
	}

	public String getFlag14() {
		return flag14;
	}

	public String getFlag15() {
		return flag15;
	}

	public String getFlag16() {
		return flag16;
	}

	public String getFullCategoryPath() {
		return fullCategoryPath;
	}

	public List<Group> getGroups() {
		return groups;
	}

	public Image getImage() {
		return image;
	}

	public File[] getImageDes() {
		return imageDes;
	}

	public File[] getImageFiles() {
		return imageFiles;
	}

	public String[] getImageFilesFileNames() {
		return imageFilesFileNames;
	}

	public File[] getImageMFiles() {
		return imageMFiles;
	}

	public List<Image> getImages() {
		return images;
	}

	public Map<String, String> getImageTypeMap() {
		return imageTypeMap;
	}

	public String getImgId() {
		return imgId;
	}

	public String[] getImgIds() {
		return imgIds;
	}

	public int getImgSize() {
		return imgSize;
	}

	public String getJsonCategoryData() throws CoreException {
		category = categoryService.get(Long.parseLong(mainCategoryId));
		categoryResult = category.getIsEndnode();
		return "jsonCategoryData";
	}

	public String getJsonCategoryPath() {
		return jsonCategoryPath;
	}

	/**
	 * 判断上下架檔期是否重覆
	 * 
	 * @return
	 * @throws ParseException
	 * @throws CoreException
	 */
	public String getJsonCheckIfRecordExist() throws ParseException, CoreException {
		Shelf shelf = new Shelf();
		shelf.setProductId(productIdParam);
		shelf.setStartDate(DateUtils.parseDate(startDate + " " + timeStart.trim(),
				new String[] { EcConstant.PATTERN_TIMESTAMP_HH_MM }));
		shelf.setEndDate(DateUtils.parseDate(endDate + " " + timeEnd.trim(),
				new String[] { EcConstant.PATTERN_TIMESTAMP_HH_MM }));
		// if (shelfService.checkIfRecordExist(shelf)) {
		// jsonShelfDateExist = "Y";
		// } else {
		// jsonShelfDateExist = "N";
		// }
		jsonShelfDateExist = "N";
		return "jsonCheckIfRecordExist";

	}

	public String getJsonOrderNotice() {
		return jsonOrderNotice;
	}

	public Product getJsonProduct() {
		return jsonProduct;
	}

	public String getJsonShelfDateExist() {
		return jsonShelfDateExist;
	}

	public String getLastMainCategoryId() {
		return lastMainCategoryId;
	}

	public String getListPrice() {
		return listPrice;
	}

	// public Long getMainCategory() {
	// return mainCategory;
	// }

	public String getMainCategoryId() {
		return mainCategoryId;
	}

	public String getMainCategoryText() {
		return mainCategoryText;
	}

	public String getMainProductIdParam() {
		return mainProductIdParam;
	}

	public Map<String, String> getMapRootCategories() {
		return mapRootCategories;
	}

	public String getMinDate() {
		return minDate;
	}

	public String getOrderNotice() {
		return orderNotice;
	}

	public String getOrganization() {
		return organization;
	}

	public String getOrganizationParam() {
		return organizationParam;
	}

	public SimplePager getPager() {
		return pager;
	}

	public String getPicDesc() {
		return picDesc;
	}

	public String[] getPicImgDescs() {
		return picImgDescs;
	}

	public String[] getPicImgDetails() {
		return picImgDetails;
	}

	public File[] getPicImgs() {
		return picImgs;
	}

	public String[] getPicImgShowSeqs() {
		return picImgShowSeqs;
	}

	// public String getPickProductId() {
	// return pickProductId;
	// }

	public String getPickupQty() {
		return pickupQty;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.Preparable#prepare()
	 */

	public String getPm() {
		return pm;
	}

	public String getPmParam() {
		return pmParam;
	}

	public String getReturnRule() {
		return returnRule;
	}

	public String[] getPrdtDelete() {
		return prdtDelete;
	}

	public Product getProduct() {
		return product;
	}

	public String getProductAttribute() {
		return productAttribute;
	}

	public String getProductAttributeParam() {
		return productAttributeParam;
	}

	public List<ProductCategory> getProductCategories() {
		return productCategories;
	}

	public ProductCategory getProductCategory() {
		return productCategory;
	}

	public Map<Long, String> getProductCategoryMap() {
		return productCategoryMap;
	}

	public String getProductIdParam() {
		return productIdParam;
	}

	public String getProductmgTypeParam() {
		return productmgTypeParam;
	}

	public String getProductName() {
		return productName;
	}

	public Map<String, String> getProductNameMap() {
		return productNameMap;
	}

	public ProductPromotionFlag getProductPromotionFlag() {
		return productPromotionFlag;
	}

	public String getPromoteName() {
		return promoteName;
	}

	public String getPromoteNameParam() {
		return promoteNameParam;
	}

	public List<Category> getRootCategories() {
		return rootCategories;
	}

	public String getSelImageType() {
		return selImageType;
	}

	public Shelf getShelf() {
		return shelf;
	}

	public String getShelfIdParam() {
		return shelfIdParam;
	}

	public String getShelfPrice() {
		return shelfPrice;
	}

	public String getShowSeq() {
		return showSeq;
	}

	public String getStartDate() {
		return startDate;
	}

	public String getStartDateParam() {
		return startDateParam;
	}

	public SupplierApplyService getSupplierApplyService() {
		return supplierApplyService;
	}

	public String getSupplierCompanyName() {
		return supplierCompanyName;
	}

	public String getSupplierId() {
		return supplierId;
	}

	public String getSupplierParam() {
		return supplierParam;
	}

	public String getTimeEnd() {
		return timeEnd;
	}

	public String getTimeStart() {
		return timeStart;
	}

	public String getToday() {
		return today;
	}

	public List<User> getUsers() {
		return users;
	}

	// public List<ViewPickProduct2> getViewPickProducts() {
	// return viewPickProducts;
	// }

	/**
	 * 初始化新增上架檔资料
	 */
	void initNewShelf() {
		shelf = new Shelf();
		shelf.setShelfStatus("SHF000");
		shelf.setShelfPrice(new BigDecimal(0));
	}

	public String loadOrderNotice() throws CoreException {
		category = categoryService.get(Long.parseLong(categoryId));
		if (category.getLevel() == "0") {
			jsonOrderNotice = productService.readOrderNotice(categoryId);
		} else {
			jsonOrderNotice = productService.readOrderNotice(category.getCategoryPath().split("/")[0]);
		}
		return "jsonLoadOrderNotice";
	}

	public void prepare() throws Exception {
		clearErrorsAndMessages();
		if (null == pager) {
			pager = new SimplePager();
		}
		if (StringUtils.isBlank(minDate)) {
			minDate = DateUtil.convertDateToString("yyyy,MM - 1,dd", DateUtil.getTodayAddDays(-50).getTime());
		}
		if (StringUtils.isBlank(today)) {
			today = DateUtil.convertDateToString("yyyy,MM - 1,dd", DateUtil.getToday().getTime());
		}

		if (null == rootCategories) {
			rootCategories = categoryService.getChild(0l);
			mapRootCategories = new HashMap<String, String>();
			for (Category rootCategory : rootCategories) {
				mapRootCategories.put(rootCategory.getId().toString(), rootCategory.getName());
			}
		}

		// 品牌列表
		// if (null == brands) {
		// criteria = new CommonCriteria();
		// brands = productService.getBrandList(0, -1, criteria, null);
		// }

		// 商品属性
		if (null == attributeMenu) {
			attributeMenu = menuService.get("Product.Attribute");
		}

		// 找出所有ｐｍ的user
		if (null == users) {
			users = userService.getByRole(Role.Default.PM.name(), Role.Type.OTHER);
		}

		// 找出a-20的部門
		groups = groupService.getList(0, -1, new CommonCriteria().addRlike("code", EcConstant.PRODUCT_PM_GROUP_CODE),
				new String[] { "code" });

		if (null == imageTypeMap) {
			imageTypeMap = new TreeMap<String, String>();
			imageTypeMap.put("MAIN", "方形主檔图");
			imageTypeMap.put("RMAIN", "长形主檔图");
			imageTypeMap.put("DESC", "说明图");
			imageTypeMap.put("IMGB", "商品图");
		}

		// 效期管理分类
		if (null == expireManageMenu) {
			expireManageMenu = menuService.get("ExpireManage.Attribute");
		}

		// 退换货条件
		returnRuleMenu = menuService.get("Order.ReturnRule");

		// brandParam = "";
		userPermissions = "";

		if (null == isScmMenu) {
			isScmMenu = menuService.get("Product.isScm");
		}
		if (null == shelfStatusMenu) {
			shelfStatusMenu = menuService.get("Shelf.Status");
		}

		if (null == shelfQueryStatusMenu) {
			shelfQueryStatusMenu = menuService.get("Shelf.QueryStatus");
		}

		logger.info("prepare ok");
	}

	public String readFullCategoryPath() throws NumberFormatException, CoreException {
		fullCategoryPath = categoryService.makeCategorieURL(Long.parseLong(categoryId), false);
		return "jsonFullCategoryPath";
	}

	/**
	 * 读商品活动简介／特色、商品活动说明文字、商品活动规格内容檔案
	 * 
	 * @param product
	 * @return
	 * @throws CoreException
	 */
	Map<String, String> readProductFromFile(String productId) throws CoreException {
		Map<String, String> tempMap = new HashMap<String, String>();
		tempMap.put("brief",
				StringUtils.isNotBlank(StringUtils.trim(productService.readFromFile(productId, "brief"))) ? StringUtils
						.trim(productService.readFromFile(productId, "brief")) : "★&nbsp;\n★&nbsp;\n★&nbsp;\n★&nbsp;\n★&nbsp;");
		StringBuffer importDescImg = new StringBuffer();
		if (StringUtils.isNotBlank(productIdParam)) {
			CommonCriteria crit = new CommonCriteria();
			crit.addEq("productId", productIdParam);
			crit.addEq("type", "DESC");
			crit.addEq("isDelete", "N");
			List<Image> images = imageService.getList(0, -1, crit, null);
			if (images.size() > 0) {
				for (Image img : images) {
					importDescImg.append("<img src='").append(ServerValue.getImgDomain() + img.getImgFilePath()).append("'>");
				}
			}
		}
		tempMap.put("importDescImg", importDescImg.toString());
		tempMap.put("description", productService.readFromFile(productId, "description"));
		tempMap.put("details", productService.readFromFile(productId, "details"));
		tempMap.put("orderNotice", productService.readFromFile(productId, "orderNotice"));
		tempMap.put("scmNotice", productService.readFromFile(productId, "scmNotice"));
		return tempMap;
	}

	/**
	 * 儲存:n選m*
	 * 
	 * @return
	 * @throws Exception
	 */
	public String savePickProduct() throws Exception {
		List<AddOnProduct> removeProducts = new ArrayList<AddOnProduct>();
		// 新增
		if (addPrds != null) {
			if (addPrds.length > 50) {// 50
				addPrds = null;
				delPrds = null;
				addActionMessage("超过50笔");
				setProductIdParam(productIdParam);
				return editPickProduct();
			}

			CommonCriteria crit = new CommonCriteria();
			crit.addEq("mainProductId", productIdParam);
			int adsize = productService.getAddOnProductList(0, -1, crit, null).size();
			if (adsize + addPrds.length > 50) {// 50
				addPrds = null;
				delPrds = null;
				addActionMessage("超过50笔");
				setProductIdParam(productIdParam);
				return editPickProduct();
			}
			addOnProducts.clear();
			for (int i = 0; i < addPrds.length; i++) {
				addOnProduct = productService.getAddOnProduct(productIdParam, addPrds[i]);
				if (addOnProduct == null) {
					addOnProduct = new AddOnProduct();
					addOnProduct.setMainProductId(productIdParam);
					addOnProduct.setAddOnProductId(addPrds[i]);
					addOnProduct.setAddOnDesc("");
					addOnProduct.setAddOnPrice(new BigDecimal(-1));
					addOnProduct.setStartDate(new Date());
					addOnProduct.setEndDate(DateUtils.addYears(new Date(), 100));
					addOnProduct.setApplyMemberRank("0");
					addOnProduct.setIsEnable("Y");
					addOnProduct.setIsDelete("N");
					Product aop = productService.get(addPrds[i]);
					addOnProduct.setAddProduct(aop);
					addOnProducts.add(addOnProduct);
				}

			}
		}

		// 移除
		if (delPrds != null) {
			AddOnProduct removeProduct = null;
			for (int i = 0; i < delPrds.length; i++) {
				removeProduct = productService.getAddOnProduct(productIdParam, delPrds[i]);
				removeProducts.add(removeProduct);
			}
		}

		productService.saveOrUpdateAddOnProductBatch(addOnProducts, removeProducts);

		Product pt = productService.get(productIdParam);
		if (pt.getStepFlag() < 4) {
			pt.setStepFlag(3);
			productService.saveOrUpdateProduct(pt, false);
		}
		addPrds = null;
		delPrds = null;
		addActionMessage("储存完成");
		setProductIdParam(productIdParam);
		return editPickProduct();
	}

	/**
	 * 新增/编辑商品主檔/flag资料
	 * 
	 * @return
	 * @throws CoreException
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @throws ParseException
	 */
	public String saveProduct() {
		try {
			BigDecimal tempBigDecimal = new BigDecimal(-1);
			if (StringUtils.isNotBlank(productIdParam)) {
				product = productService.get(productIdParam);
				product.setOldMainCategoryID(product.getMainCategoryID());
				category = categoryService.get(Long.valueOf(String.valueOf(mainCategoryId)));
				if (null == category || category.getIsDelete().equalsIgnoreCase("Y")) {
					addActionError("儲存失敗,主分类资料不正确");
					return "editProduct";
				}
				Category rootCategory = categoryService.get(Long.parseLong(category.getCategoryPath().split("/")[0]));
				if (null == rootCategory) {
					addActionError("儲存失敗,主分类资料不正确");
					return "editProduct";
				}
				if (rootCategory.getIsDelete().equals("Y")) {
					addActionError("儲存失敗,主分类资料不正确");
					return "editProduct";
				}
				if (StringUtils.equals("Y", nmMustOrderBuy)) {
					Long nmlAddOnCount = productService.getNmlAddOnCount(productIdParam);
					if (nmlAddOnCount.intValue() > 0) {
						addActionError("儲存失敗,搭售商品中含有一般、赠品或配件商品，请先移除后再设定");
						return "editProduct";
					}
				}
				if (StringUtils.equals("N", nmMustOrderBuy)) {
					Long luxAddOnCount = productService.getLuxAddOnCount(productIdParam);
					if (luxAddOnCount.intValue() > 0) {
						addActionError("儲存失敗,搭售商品中含有限立即购买商品，请先移除后再设定");
						return "editProduct";
					}
				}
				if (null == product.getProductPromotionFlag()) {
					productPromotionFlag = new ProductPromotionFlag();
				} else {
					productPromotionFlag = product.getProductPromotionFlag();
				}
				if (StringUtils.isNotBlank(isScm)) {
					product.setIsScm(isScm);
				}

			} else {
				product = new Product();
				product.setProductWeight(new BigDecimal(0).setScale(1, BigDecimal.ROUND_FLOOR));
				product.setProductHeight(tempBigDecimal);
				product.setProductLength(tempBigDecimal);
				product.setProductVolume(tempBigDecimal);
				product.setProductWidth(tempBigDecimal);
				product.setMaxPOQuantity(-1);
				product.setMinPOQuantity(-1);
				if (StringUtils.isNotBlank(isScm)) {
					product.setIsScm(isScm);
				}
				product.setProductCost(tempBigDecimal);
				productPromotionFlag = new ProductPromotionFlag();
			}
			if (Arrays.asList("010000", "010001").contains(supplierId)
					&& StringUtils.equalsIgnoreCase("Y", product.getIsScm())) {
				addActionError("若供应商为万美供应商，采购模式不可为转单");
				return "editProduct";
			}

			if (Arrays.asList("010000", "010001").contains(supplierId)) {
				if (StringUtils.equalsIgnoreCase("Y", product.getIsScm())) {
					addActionError("若供应商为万美供应商，采购模式不可为转单");
					return "editProduct";
				}
				if (StringUtils.isNotBlank(editTwSupplier)) {
					product.setTwSupplierId(editTwSupplier);
				} else {
					product.setTwSupplierId("");
				}
			}

			// 商品主檔
			product.setProductName(productName);
			product.setProductBrief(brief);
			product.setProductDescription(description);
			product.setProductDetails(details);
			if (StringUtils.isNotBlank(orderNotice)) {
				product.setProductOrderNotice(orderNotice);
			}
			if (StringUtils.isNotBlank(scmNotice)) {
				product.setScmNotice(scmNotice);
			}
			product.setProductStatus("PRD500");
			product.setListPrice(new BigDecimal(listPrice).setScale(1, BigDecimal.ROUND_FLOOR));
			product.setProductType(6);// n選m
			product.setSupplierId(supplierId);
			product.setProductBrand(editbrand);

			if (StringUtils.isBlank(mainCategoryId)) {
				addActionError("主分类资料不得为空");
				return "editProduct";
			} else {
				category = categoryService.get(Long.valueOf(mainCategoryId));
				if (null == category || category.getIsDelete().equalsIgnoreCase("Y")) {
					addActionError("儲存失敗,主分类资料不正确");
					return "editProduct";
				}
				product.setMainCategoryID(Integer.valueOf(mainCategoryId));
				product.setMainCategoryPath(category.getCategoryPath());
				product.setCategory(category);
			}
			product.setIsDelete(productAttribute);
			product.setReturnRule(returnRule);
			product.setNmMustOrderBuy(nmMustOrderBuy);
			product.setIsVirtual("Y");
			product.setProductUnit("组");

			if (StringUtils.isNotBlank(showSeq)) {
				product.setShowSeq(Integer.parseInt(showSeq));
			}

			product.setPmID(pm);
			product.setOrganizationPath(organization);

			if (StringUtils.isNotBlank(expireManage)) {
				product.setExpireManage(expireManage);
			} else {
				product.setExpireManage("EM01");
			}

			if (StringUtils.isNotBlank(isAntiUnpacking)) {
				product.setIsAntiUnpacking(isAntiUnpacking);
			} else {
				product.setIsAntiUnpacking("N");
			}
			if (StringUtils.isNotBlank(graphicType)) {
				product.setGraphicType(graphicType);
			} else {
				product.setGraphicType("S");
			}
			if (StringUtils.isNotBlank(isValidateNum)) {
				product.setIsValidateNum(isValidateNum);
			} else {
				product.setIsValidateNum("N");
			}

			if (StringUtils.isBlank(prpsShelfPrice)) {
				product.setPrpsShelfPrice(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				product.setPrpsShelfPrice(new BigDecimal(prpsShelfPrice).setScale(2, BigDecimal.ROUND_FLOOR));
			}

			if (StringUtils.equalsIgnoreCase(flag04, "Y")) {
				productPromotionFlag.setFlag04(flag04);
			} else {
				productPromotionFlag.setFlag04(null);
			}

			if (StringUtils.equalsIgnoreCase(flag05, "Y")) {
				productPromotionFlag.setFlag05(flag05);
			} else {
				productPromotionFlag.setFlag05(null);
			}

			if (StringUtils.equalsIgnoreCase(flag06, "Y")) {
				productPromotionFlag.setFlag06(flag06);
			} else {
				productPromotionFlag.setFlag06(null);
			}

			if (StringUtils.equalsIgnoreCase(flag16, "Y")) {
				productPromotionFlag.setFlag16(flag16);
			} else {
				productPromotionFlag.setFlag16(null);
			}

			/* 商品分身 */
			String[] splitData = StringUtils.split(finalAddOnData, ";");

			editProductCategories = new ArrayList<ProductCategory>();
			ProductCategory pc = null;
			Category category = null;

			for (int i = 0; i < splitData.length; i++) {
				String[] sUpdate = StringUtils.split(splitData[i], ",");
				category = categoryService.getCategoryNonePermission(Long.parseLong(sUpdate[0]));
				pc = new ProductCategory();
				pc.setProductId(product.getProductId());
				pc.setCategoryId(Long.parseLong(sUpdate[0]));
				pc.setCategoryName(category.getName());
				pc.setCategoryPath(category.getCategoryPath());
				pc.setShowSeq(Integer.parseInt(sUpdate[1]));
				editProductCategories.add(pc);
			}
			product.setProductCategories(editProductCategories);
			if (product.getStepFlag() < 2) {
				product.setStepFlag(2);
			}
			product = productService.saveOrUpdateProductByPickProduct(product, productPromotionFlag);
			productIdParam = product.getProductId();
			addActionMessage("储存完成");

			if ("next".equalsIgnoreCase(saveFlag)) {
				HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
						ServletActionContext.HTTP_RESPONSE);

				response.sendRedirect(ServerValue.getMidContextPath() + "/image2/edit.do?productId=" + product.getProductId());

			} else {
				return editProduct();
			}

		} catch (Exception e) {
			addActionError("新增/修改失败");
		}
		return editProduct();
	}

	/**
	 * 储存上架檔资料
	 * 
	 * @return
	 * @throws ParseException
	 * @throws NumberFormatException
	 * @throws CoreException
	 */
	public String saveShelf() throws ParseException, NumberFormatException, CoreException {
		try {
			Date tempStartDate = null;
			Date tempEndDate = null;
			if (StringUtils.isBlank(shelfIdParam)) {
				product = productService.get(productIdParam);
				shelf = new Shelf();
				shelf.setProductId(productIdParam);

				CommonCriteria crit = new CommonCriteria();
				crit.addEq("productId", productIdParam);
				crit.addEq("shelfStatus", "SHF500");
				List<Shelf> shelfs = shelfService.getList(0, -1, crit, null);
				if (shelfs.size() > 0) {
					for (Shelf sf : shelfs) {
						Date aDate = format.parse(startDate + " " + timeStart.trim() + ":00");
						if (aDate.compareTo(sf.getStartDate()) == 0) {
							addActionMessage("上架档起始日期与已有上架档重复，请重新输入");
							return shelfSearch();
						}
					}
				}
				shelf.setStartDate(DateUtils.parseDate(startDate + " " + timeStart.trim() + ":00",
						new String[] { EcConstant.PATTERN_TIMESTAMP }));
			} else {
				shelf = shelfService.get(Long.parseLong(shelfIdParam));
				product = productService.get(shelf.getProductId());
			}
			if (StringUtils.isBlank(validateNumParam)) {
				shelf.setIsValidateNum("N");
			} else {
				shelf.setIsValidateNum(validateNumParam);
			}
			if (StringUtils.isBlank(limitBuyParam)) {
				shelf.setIsLimitBuy("N");
			} else {
				shelf.setIsLimitBuy(limitBuyParam);
			}
			tempStartDate = shelf.getStartDate();
			tempEndDate = shelf.getEndDate();
			shelf.setPromoteName(promoteNameParam);
			shelf.setShelfPrice(new BigDecimal(shelfPrice).setScale(1, BigDecimal.ROUND_FLOOR));

			if (StringUtils.isBlank(endDate)) {
				if (StringUtils.isBlank(timeEnd.trim())) {
					timeEnd = "23:59";
				}
				shelf.setEndDate(DateUtils.parseDate("2999-12-31" + " " + timeEnd.trim() + ":59",
						new String[] { EcConstant.PATTERN_TIMESTAMP }));
			} else {
				shelf.setEndDate(DateUtils.parseDate(endDate + " " + timeEnd.trim() + ":59",
						new String[] { EcConstant.PATTERN_TIMESTAMP }));
			}
			shelf.setShelfStatus("SHF500");
			// if (shelfService.checkIfRecordExist(shelf)) {
			// addActionError("请勿新增重复的上架檔期");
			// return editShelf();
			// }
			shelf.setShelfType("1");// defult 一般
			shelf.setGiveBonus(0);// 赠送赠物金点数default 0
			product.setPickupQty(Integer.parseInt(pickupQty));
			shelf = productService.saveOrUpdateShelfByPickProduct(shelf, product);
			shelfIdParam = shelf.getShelfId().toString();

			// 更新限購商品
			timeLimitSaleService.addTimeLimitProd(product, shelf);

			Product pt = productService.get(productIdParam);
			if (pt.getStepFlag() < 4) {
				pt.setStepFlag(4);
				productService.saveOrUpdateProduct(pt, false);
			}

			addActionMessage("发布商品成功");
		} catch (CoreException e) {
			addActionError(e.getMessage());
			// return editShelf();
		}
		// return editShelf();
		return shelfSearch();
	}

	/**
	 * ｎ选ｍ上下架查询列表
	 * 
	 * @return
	 * @throws CoreException
	 * @throws ParseException
	 */
	public String shelfSearch() {
		criteria = new CommonCriteria();
		if (StringUtils.isNotBlank(productIdParam)) {
			product = productService.get(productIdParam);
			criteria.addEq("productId", productIdParam);
		}
		if (StringUtils.isNotBlank(shelfStParam)) {
			criteria.addEq("shelfStatus", shelfStParam);
		}
		if (null == shelfStParam) {
			criteria.addNe("shelfStatus", "SHF000");
		}
		shelfs = shelfService.getList(0, -1, criteria, null);
		shelfNow = shelfService.getActiveShelfByProductId(productIdParam);
		nowStep = "4";
		return "shelflist";
	}

	/**
	 * ｎ选ｍ上下架查询列表-批次下架
	 * 
	 * @return
	 * @throws Exception
	 */
	public String updateShelfStatus() throws Exception {
		if (null != shelfStatus) {
			for (int i = 0; i < shelfStatus.length; i++) {
				Shelf shelf = shelfService.get(Long.parseLong(shelfStatus[i]));
				shelf.setShelfStatus("SHF700");
				shelfService.saveOrUpdateShelf(shelf);
			}
			addActionMessage("异动笔数:" + shelfStatus.length);
		}
		return shelfSearch();
	}

	/**
	 * ｎ选ｍ商品查询列表
	 * 
	 * @return
	 * @throws CoreException
	 * @throws ParseException
	 */
	public String search() {
		try {
			Map<String, String> queryParam = new HashMap<String, String>();

			if (StringUtils.isNotBlank(mainProductIdParam)) {
				queryParam.put("productId", mainProductIdParam.trim());
			}
			if (StringUtils.isNotBlank(promoteNameParam)) {
				queryParam.put("promoteName", promoteNameParam.trim());
			}
			if (StringUtils.isNotBlank(addonProductIdParam)) {
				queryParam.put("addonProductId", addonProductIdParam.trim());
			}
			if (StringUtils.isNotBlank(startDateParam)) {
				queryParam.put("startDate", startDateParam);
			}
			if (StringUtils.isNotBlank(endDateParam)) {
				queryParam.put("endDate", endDateParam);
			}
			if (StringUtils.isNotBlank(productAttributeParam)) {
				queryParam.put("isDelete", productAttributeParam);
			} else {
				productAttributeParam = "N";
				queryParam.put("isDelete", productAttributeParam);
			}
			if (StringUtils.isNotBlank(supplierParam)) {
				queryParam.put("supplierId", supplierParam);
			}

			if (StringUtils.isNotBlank(brandParam)) {
				queryParam.put("productBrand", brandParam);
			}

			if (StringUtils.isNotBlank(organizationParam)) {
				queryParam.put("organizationPath", organizationParam);
			}

			if (StringUtils.isNotBlank(pmParam)) {
				queryParam.put("pmID", pmParam);
			}

			if (StringUtils.isNotBlank(returnRule)) {
				queryParam.put("returnRule", returnRule);
			}

			if (StringUtils.isNotBlank(categoryLevel1Param) && StringUtils.isNotBlank(categoryLevel2Param)) {
				queryParam.put("categoryPath", categoryLevel1Param + "/" + categoryLevel2Param + "/%");
			} else if (StringUtils.isNotBlank(categoryLevel1Param) && StringUtils.isBlank(categoryLevel2Param)) {
				queryParam.put("categoryPath", categoryLevel1Param + "/%");
			}

			if (StringUtils.isNotBlank(isScmParam)) {
				queryParam.put("isScm", isScmParam);
			}

			if (StringUtils.isNotBlank(nmMustOrderBuyParam)) {
				queryParam.put("nmMustOrderBuy", nmMustOrderBuyParam);
			}

			int entitySize = productService.getPickProductListSize(queryParam).intValue();
			pager.setTotalSize(entitySize);
			int firstResult = pager.getCurrentPage() * pager.getPageRecord();
			int maxResults = (firstResult + pager.getPageRecord()) > entitySize ? entitySize : firstResult
					+ pager.getPageRecord();
			queryParam.put("firstResult", String.valueOf(firstResult));
			queryParam.put("maxResults", String.valueOf(maxResults));
			pickProductList = productService.getPickProductList(queryParam);
		} catch (CoreException e) {
			addActionError("n选m商品查询失败");
		}
		return "list";
	}

	public void setAddonProductIdParam(String addonProductIdParam) {
		this.addonProductIdParam = addonProductIdParam;
	}

	// public void setBrand(String brand) {
	// this.brand = brand;
	// }
	//
	// public void setBrands(List<Brand> brands) {
	// this.brands = brands;
	// }

	public void setAddOnProducts(List<AddOnProduct> addOnProducts) {
		this.addOnProducts = addOnProducts;
	}

	public void setAttributeMenu(Menu attributeMenu) {
		this.attributeMenu = attributeMenu;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public void setBrandParam(String brandParam) {
		this.brandParam = brandParam;
	}

	public void setBrief(String brief) {
		this.brief = brief;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public void setCategoryLevel1Param(String categoryLevel1Param) {
		this.categoryLevel1Param = categoryLevel1Param;
	}

	public void setCategoryLevel2Param(String categoryLevel2Param) {
		this.categoryLevel2Param = categoryLevel2Param;
	}

	// public void setCategoryPath(String categoryPath) {
	// this.categoryPath = categoryPath;
	// }

	public void setCategoryResult(String categoryResult) {
		this.categoryResult = categoryResult;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCriteria(CommonCriteria criteria) {
		this.criteria = criteria;
	}

	public void setDeletePic(String[] deletePic) {
		this.deletePic = deletePic;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public void setEditFlag(String editFlag) {
		this.editFlag = editFlag;
	}

	public void setEditProductCategories(List<ProductCategory> editProductCategories) {
		this.editProductCategories = editProductCategories;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public void setEndDateParam(String endDateParam) {
		this.endDateParam = endDateParam;
	}

	public void setFileMap(Map<String, String> fileMap) {
		this.fileMap = fileMap;
	}

	public void setFinalAddOnData(String finalAddOnData) {
		this.finalAddOnData = finalAddOnData;
	}

	public void setFinalRemoveData(String finalRemoveData) {
		this.finalRemoveData = finalRemoveData;
	}

	public void setFlag01(String flag01) {
		this.flag01 = flag01;
	}

	public void setFlag02(String flag02) {
		this.flag02 = flag02;
	}

	public void setFlag03(String flag03) {
		this.flag03 = flag03;
	}

	public void setFlag04(String flag04) {
		this.flag04 = flag04;
	}

	public void setFlag05(String flag05) {
		this.flag05 = flag05;
	}

	public void setFlag06(String flag06) {
		this.flag06 = flag06;
	}

	public void setFlag07(String flag07) {
		this.flag07 = flag07;
	}

	public void setFlag08(String flag08) {
		this.flag08 = flag08;
	}

	public void setFlag09(String flag09) {
		this.flag09 = flag09;
	}

	public void setFlag10(String flag10) {
		this.flag10 = flag10;
	}

	public void setFlag11(String flag11) {
		this.flag11 = flag11;
	}

	public void setFlag12(String flag12) {
		this.flag12 = flag12;
	}

	public void setFlag13(String flag13) {
		this.flag13 = flag13;
	}

	public void setFlag14(String flag14) {
		this.flag14 = flag14;
	}

	public void setFlag15(String flag15) {
		this.flag15 = flag15;
	}

	public void setFlag16(String flag16) {
		this.flag16 = flag16;
	}

	public void setFullCategoryPath(String fullCategoryPath) {
		this.fullCategoryPath = fullCategoryPath;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}

	public void setImage(Image image) {
		this.image = image;
	}

	public void setImageDes(File[] imageDes) {
		this.imageDes = imageDes;
	}

	public void setImageFiles(File[] imageFiles) {
		this.imageFiles = imageFiles;
	}

	public void setImageFilesFileNames(String[] imageFilesFileNames) {
		this.imageFilesFileNames = imageFilesFileNames;
	}

	public void setImageMFiles(File[] imageMFiles) {
		this.imageMFiles = imageMFiles;
	}

	public void setImages(List<Image> images) {
		this.images = images;
	}

	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	public void setImageTypeMap(Map<String, String> imageTypeMap) {
		this.imageTypeMap = imageTypeMap;
	}

	public void setImgId(String imgId) {
		this.imgId = imgId;
	}

	public void setImgIds(String[] imgIds) {
		this.imgIds = imgIds;
	}

	public void setImgSize(int imgSize) {
		this.imgSize = imgSize;
	}

	public void setJsonCategoryPath(String jsonCategoryPath) {
		this.jsonCategoryPath = jsonCategoryPath;
	}

	public void setJsonOrderNotice(String jsonOrderNotice) {
		this.jsonOrderNotice = jsonOrderNotice;
	}

	public void setJsonProduct(Product jsonProduct) {
		this.jsonProduct = jsonProduct;
	}

	public void setJsonShelfDateExist(String jsonShelfDateExist) {
		this.jsonShelfDateExist = jsonShelfDateExist;
	}

	public void setLastMainCategoryId(String lastMainCategoryId) {
		this.lastMainCategoryId = lastMainCategoryId;
	}

	public void setListPrice(String listPrice) {
		this.listPrice = listPrice;
	}

	// public void setMainCategory(Long mainCategory) {
	// this.mainCategory = mainCategory;
	// }

	public void setMainCategoryId(String mainCategoryId) {
		this.mainCategoryId = mainCategoryId;
	}

	public void setMainCategoryText(String mainCategoryText) {
		this.mainCategoryText = mainCategoryText;
	}

	public void setMainProductIdParam(String mainProductIdParam) {
		this.mainProductIdParam = mainProductIdParam;
	}

	public void setMapRootCategories(Map<String, String> mapRootCategories) {
		this.mapRootCategories = mapRootCategories;
	}

	public void setMenuService(DomainService<Menu> menuService) {
		this.menuService = menuService;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public void setOrderNotice(String orderNotice) {
		this.orderNotice = orderNotice;
	}

	public void setOrganization(String organization) {
		this.organization = organization;
	}

	public void setOrganizationParam(String organizationParam) {
		this.organizationParam = organizationParam;
	}

	public void setPager(SimplePager pager) {
		this.pager = pager;
	}

	public void setPicDesc(String picDesc) {
		this.picDesc = picDesc;
	}

	public void setPicImgDescs(String[] picImgDescs) {
		this.picImgDescs = picImgDescs;
	}

	public void setPicImgDetails(String[] picImgDetails) {
		this.picImgDetails = picImgDetails;
	}

	public void setPicImgs(File[] picImgs) {
		this.picImgs = picImgs;
	}

	public void setPicImgShowSeqs(String[] picImgShowSeqs) {
		this.picImgShowSeqs = picImgShowSeqs;
	}

	// public void setPickProductId(String pickProductId) {
	// this.pickProductId = pickProductId;
	// }

	public void setPickupQty(String pickupQty) {
		this.pickupQty = pickupQty;
	}

	public void setPm(String pm) {
		this.pm = pm;
	}

	public void setPmParam(String pmParam) {
		this.pmParam = pmParam;
	}

	public void setReturnRule(String returnRule) {
		this.returnRule = returnRule;
	}

	public void setPrdtDelete(String[] prdtDelete) {
		this.prdtDelete = prdtDelete;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setProductAttribute(String productAttribute) {
		this.productAttribute = productAttribute;
	}

	public void setProductAttributeParam(String productAttributeParam) {
		this.productAttributeParam = productAttributeParam;
	}

	public void setProductCategories(List<ProductCategory> productCategories) {
		this.productCategories = productCategories;
	}

	public void setProductCategory(ProductCategory productCategory) {
		this.productCategory = productCategory;
	}

	public void setProductCategoryMap(Map<Long, String> productCategoryMap) {
		this.productCategoryMap = productCategoryMap;
	}

	public void setProductIdParam(String productIdParam) {
		this.productIdParam = productIdParam;
	}

	public void setProductmgTypeParam(String productmgTypeParam) {
		this.productmgTypeParam = productmgTypeParam;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public void setProductNameMap(Map<String, String> productNameMap) {
		this.productNameMap = productNameMap;
	}

	public void setProductPromotionFlag(ProductPromotionFlag productPromotionFlag) {
		this.productPromotionFlag = productPromotionFlag;
	}

	public void setProductService(Product2Service productService) {
		this.productService = productService;
	}

	public void setPromoteName(String promoteName) {
		this.promoteName = promoteName;
	}

	public void setPromoteNameParam(String promoteNameParam) {
		this.promoteNameParam = promoteNameParam;
	}

	public void setRootCategories(List<Category> rootCategories) {
		this.rootCategories = rootCategories;
	}

	public void setSelImageType(String selImageType) {
		this.selImageType = selImageType;
	}

	public void setShelf(Shelf shelf) {
		this.shelf = shelf;
	}

	public void setShelfIdParam(String shelfIdParam) {
		this.shelfIdParam = shelfIdParam;
	}

	public void setShelfPrice(String shelfPrice) {
		this.shelfPrice = shelfPrice;
	}

	public void setShelfService(ShelfService shelfService) {
		this.shelfService = shelfService;
	}

	public void setShowSeq(String showSeq) {
		this.showSeq = showSeq;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public void setStartDateParam(String startDateParam) {
		this.startDateParam = startDateParam;
	}

	public void setSupplierApplyService(SupplierApplyService supplierApplyService) {
		this.supplierApplyService = supplierApplyService;
	}

	public void setSupplierCompanyName(String supplierCompanyName) {
		this.supplierCompanyName = supplierCompanyName;
	}

	public void setSupplierId(String supplierId) {
		this.supplierId = supplierId;
	}

	public void setSupplierParam(String supplierParam) {
		this.supplierParam = supplierParam;
	}

	public void setTimeEnd(String timeEnd) {
		this.timeEnd = timeEnd;
	}

	public void setTimeStart(String timeStart) {
		this.timeStart = timeStart;
	}

	public void setToday(String today) {
		this.today = today;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	// public void setViewPickProducts(List<ViewPickProduct2> viewPickProducts) {
	// this.viewPickProducts = viewPickProducts;
	// }

	public String toEditImgDetail() {
		if (StringUtils.isNotBlank(imgId)) {
			image = imageService.get(Long.parseLong(imgId));
		}
		setImage(image);
		return "editImgDetail";
	}

	/**
	 * 上传商品图及说明图檔
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String uploadProdImg() throws CoreException {
		try {
			if (null != imageFiles || null != imageMFiles) {
				if (null != imageFiles) {
					imageService.uploadImage(productIdParam, productmgTypeParam, imageFiles, imageFilesFileNames, picDesc);
					if (StringUtils.equals("DESC", productmgTypeParam)) {
						selImageType = "DESC";
					} else {
						selImageType = "IMGB";
					}
				}
				if (null != imageMFiles) {
					imageService.uploadImage(productIdParam, productmgTypeParam, imageMFiles, imageFilesFileNames, picDesc);
					selImageType = productmgTypeParam;
				}
				// 开始删图
				File fileDel = new File(ServerValue.getMidApachePath() + File.separator + "PImg" + File.separator);
				File[] files = fileDel.listFiles(new FilenameFilter() {
					public boolean accept(File dir, String name) {
						return name.length() != 4
								&& ("logo_ok_b.png,blank_75.gif,blank_500.gif,blank_50.gif,blank_250.gif,blank_135.gif,blank_100.gif,tmpZip,blank_r93.gif,blank_r130.gif,blank_r180.gif,blank_r330.gif,blank_r225.gif,blank_r530.gif,40x40.gif,blank_225.gif,blank_r99.gif"
										.indexOf(name) == -1);
					}
				});
				if (null != files) {
					for (int i = 0; i < files.length; i++) {
						FileUtils.forceDelete(files[i]);
					}
				}
			}
			imageFiles = null;
			imageMFiles = null;
		} catch (Exception e) {
			addActionError(e.fillInStackTrace().toString());
		}
		return viewUploadProdImg();
	}

	/**
	 * 检视上传商品图及说明图檔
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String viewUploadProdImg() throws CoreException {
		try {
			if (StringUtils.isBlank(productIdParam) || StringUtils.length(productIdParam) != 8
					|| !NumberUtils.isNumber(productIdParam)) {
				addActionError("传入参数错误");
			} else {
				product = productService.get(productIdParam);
				if (null == product) {
					addActionError("查无商品资料(或无该权限查看)");
				} else {
					shelf = checkShelfId(shelfIdParam);
					CommonCriteria crit = new CommonCriteria();
					crit.addNe("isDelete", "Y");
					crit.addRlike("productId", product.getProductId());
					if (StringUtils.isBlank(selImageType)) {
						selImageType = "MAIN";
					}
					crit.addEq("type", selImageType);
					String[] sort = { "type", "showSeq asc", "id asc" };
					images = imageService.getList(0, -1, crit, sort);

					// 商品圖筆數(大小圖加起來不可大於20筆)
					if (StringUtils.isNotBlank(productIdParam)) {
						crit = new CommonCriteria();
						crit.addEq("productId", productIdParam);
						List<String> types = new ArrayList<String>();
						types.add("IMGB");
						types.add("IMGS");
						crit.addIn("type", types);
						crit.addNe("isDelete", "Y");
						imgSize = imageService.getListSize(crit).intValue();
					}
				}
			}
		} catch (Exception e) {
			addActionError(e.fillInStackTrace().toString());
		}
		return "viewUploadProdImg";
	}

	public String getEditbrand() {
		return editbrand;
	}

	public void setEditbrand(String editbrand) {
		this.editbrand = editbrand;
	}

	public String getIsScm() {
		return isScm;
	}

	public void setIsScm(String isScm) {
		this.isScm = isScm;
	}

	public String getScmNotice() {
		return scmNotice;
	}

	public void setScmNotice(String scmNotice) {
		this.scmNotice = scmNotice;
	}

	public Menu getExpireManageMenu() {
		return expireManageMenu;
	}

	public void setExpireManageMenu(Menu expireManageMenu) {
		this.expireManageMenu = expireManageMenu;
	}

	public Menu getReturnRuleMenu() {
		return returnRuleMenu;
	}

	public void setReturnRuleMenu(Menu returnRuleMenu) {
		this.returnRuleMenu = returnRuleMenu;
	}

	public String getExpireManage() {
		return expireManage;
	}

	public void setExpireManage(String expireManage) {
		this.expireManage = expireManage;
	}

	public String getIsAntiUnpacking() {
		return isAntiUnpacking;
	}

	public void setIsAntiUnpacking(String isAntiUnpacking) {
		this.isAntiUnpacking = isAntiUnpacking;
	}

	public String getPrpsShelfPrice() {
		return prpsShelfPrice;
	}

	public void setPrpsShelfPrice(String prpsShelfPrice) {
		this.prpsShelfPrice = prpsShelfPrice;
	}

	public String getGraphicType() {
		return graphicType;
	}

	public void setGraphicType(String graphicType) {
		this.graphicType = graphicType;
	}

	public String getIsValidateNum() {
		return isValidateNum;
	}

	public void setIsValidateNum(String isValidateNum) {
		this.isValidateNum = isValidateNum;
	}

	public String getUserPermissions() {
		return userPermissions;
	}

	public void setUserPermissions(String userPermissions) {
		this.userPermissions = userPermissions;
	}

	public String getIsScmParam() {
		return isScmParam;
	}

	public void setIsScmParam(String isScmParam) {
		this.isScmParam = isScmParam;
	}

	public String getNmMustOrderBuy() {
		return nmMustOrderBuy;
	}

	public void setNmMustOrderBuy(String nmMustOrderBuy) {
		this.nmMustOrderBuy = nmMustOrderBuy;
	}

	public List<Map<String, Object>> getPickProductList() {
		return pickProductList;
	}

	public void setPickProductList(List<Map<String, Object>> pickProductList) {
		this.pickProductList = pickProductList;
	}

	public String getTwSupplierCompanyName() {
		return twSupplierCompanyName;
	}

	public void setTwSupplierCompanyName(String twSupplierCompanyName) {
		this.twSupplierCompanyName = twSupplierCompanyName;
	}

	public String getEditTwSupplier() {
		return editTwSupplier;
	}

	public void setEditTwSupplier(String editTwSupplier) {
		this.editTwSupplier = editTwSupplier;
	}

	public String getCopy() {
		return copy;
	}

	public void setCopy(String copy) {
		this.copy = copy;
	}

	public String getParamProductId() {
		return paramProductId;
	}

	public void setParamProductId(String paramProductId) {
		this.paramProductId = paramProductId;
	}

	public Map<String, String> getAddmProductSupplierMap() {
		return addmProductSupplierMap;
	}

	public void setAddmProductSupplierMap(Map<String, String> addmProductSupplierMap) {
		this.addmProductSupplierMap = addmProductSupplierMap;
	}

	public List<String> getNewAddProducts() {
		return newAddProducts;
	}

	public void setNewAddProducts(List<String> newAddProducts) {
		this.newAddProducts = newAddProducts;
	}

	public String[] getAddPrds() {
		return addPrds;
	}

	public void setAddPrds(String[] addPrds) {
		this.addPrds = addPrds;
	}

	public String[] getDelPrds() {
		return delPrds;
	}

	public void setDelPrds(String[] delPrds) {
		this.delPrds = delPrds;
	}

	public Map<String, String> getModifymProductSupplierMap() {
		return modifymProductSupplierMap;
	}

	public void setModifymProductSupplierMap(Map<String, String> modifymProductSupplierMap) {
		this.modifymProductSupplierMap = modifymProductSupplierMap;
	}

	public Map<String, String> getModifymProductScmMap() {
		return modifymProductScmMap;
	}

	public void setModifymProductScmMap(Map<String, String> modifymProductScmMap) {
		this.modifymProductScmMap = modifymProductScmMap;
	}

	public List<Shelf> getShelfs() {
		return shelfs;
	}

	public void setShelfs(List<Shelf> shelfs) {
		this.shelfs = shelfs;
	}

	public String[] getShelfStatus() {
		return shelfStatus;
	}

	public void setShelfStatus(String[] shelfStatus) {
		this.shelfStatus = shelfStatus;
	}

	public String getShelfStParam() {
		return shelfStParam;
	}

	public void setShelfStParam(String shelfStParam) {
		this.shelfStParam = shelfStParam;
	}

	public String getValidateNumParam() {
		return validateNumParam;
	}

	public void setValidateNumParam(String validateNumParam) {
		this.validateNumParam = validateNumParam;
	}

	public Menu getShelfStatusMenu() {
		return shelfStatusMenu;
	}

	public void setShelfStatusMenu(Menu shelfStatusMenu) {
		this.shelfStatusMenu = shelfStatusMenu;
	}

	public Shelf getShelfNow() {
		return shelfNow;
	}

	public void setShelfNow(Shelf shelfNow) {
		this.shelfNow = shelfNow;
	}

	public String getLimitBuyParam() {
		return limitBuyParam;
	}

	public void setLimitBuyParam(String limitBuyParam) {
		this.limitBuyParam = limitBuyParam;
	}

	public String getMainCategoryPath() {
		return mainCategoryPath;
	}

	public void setMainCategoryPath(String mainCategoryPath) {
		this.mainCategoryPath = mainCategoryPath;
	}

	public String getTempCategoryFullPath() {
		return tempCategoryFullPath;
	}

	public void setTempCategoryFullPath(String tempCategoryFullPath) {
		this.tempCategoryFullPath = tempCategoryFullPath;
	}

	public String getSaveFlag() {
		return saveFlag;
	}

	public void setSaveFlag(String saveFlag) {
		this.saveFlag = saveFlag;
	}

	public String getNowStep() {
		return nowStep;
	}

	public void setNowStep(String nowStep) {
		this.nowStep = nowStep;
	}

	public Menu getShelfQueryStatusMenu() {
		return shelfQueryStatusMenu;
	}

	public void setShelfQueryStatusMenu(Menu shelfQueryStatusMenu) {
		this.shelfQueryStatusMenu = shelfQueryStatusMenu;
	}

	public Menu getIsScmMenu() {
		return isScmMenu;
	}

	public void setIsScmMenu(Menu isScmMenu) {
		this.isScmMenu = isScmMenu;
	}

	public String getNmMustOrderBuyParam() {
		return nmMustOrderBuyParam;
	}

	public void setNmMustOrderBuyParam(String nmMustOrderBuyParam) {
		this.nmMustOrderBuyParam = nmMustOrderBuyParam;
	}

}
